import { Body, Controller, Get, Post } from "@nestjs/common";
import { CreateLog, Public } from "@/common/decorators";
import { AuthService } from "./auth.service";
import { SignInDto } from "./dto/sign-in.dto";

@Controller("auth")
export class AuthController {
    constructor(private authService: AuthService) {}

    /** 账号密码登录 */
    @Public()
    @CreateLog({ module: "认证服务", type: "query", action: "账号密码登录" }, null, false)
    @Post("signInByUsername")
    signInByUsername(@Body() signInDto: SignInDto) {
        return this.authService.signInByUsername(signInDto);
    }

    /** 获取登录验证码 */
    @Public()
    @Get("getSignInCaptcha")
    getSignInCaptcha() {
        return this.authService.generateCaptcha();
    }

    /** 刷新token */
    @Public()
    @CreateLog({ module: "认证服务", type: "query", action: "刷新Token" }, null, false)
    @Post("refreshAccessToken")
    refreshAccessToken(@Body("refreshToken") refreshToken: string) {
        return this.authService.refreshAccessToken(refreshToken);
    }

    /** 根据角色列表获取权限列表 */
    @Post("findPermissions")
    findPermissions(@Body("roles") roles: string[]) {
        return this.authService.findPermissions(roles);
    }
}
